package com.ashin.controller;

import com.ashin.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Ashin
 * @Date: 2021/4/13
 * @Description: com.ashin.controller
 * @Version: 1.0.0
 */
@RequestMapping("/users")
@RestController

public class UserController {

    @Autowired
    private JdbcTemplate userRepository;


    @GetMapping("/{id}")
    public User findById(@PathVariable Long id) {
        RowMapper<User> rowMapper = new BeanPropertyRowMapper<User>(User.class);
        User user = this.userRepository.queryForObject("select * from user where id=?", rowMapper, id);

        return user;
    }

}
